package Solutions
func makeIntegerBeautiful(n int64, target int) int64 {
    sum:=BitSum(n)
	dif := sum - target
	ans := int64(0)
	mul := 1
	for n > 0&&dif>0 {
		t := int(n % 10)
        if t==0{
            n/=10
            mul*=10
            continue
        }
		dif-=t
        dif++
        ans+=int64((10-t)*mul)
		mul *= 10
        n/=10
        n++
        sum=BitSum(n)
        if sum<target{
            return ans
        }
        dif=sum-target
	}
	return ans

}

func BitSum(n int64)int{
    sum := 0
	tn := n
	for tn > 0 {
		sum += int(tn % 10)
		tn /= 10
	}
    return sum
}
